#encoding:utf8
'''
网页抓取类
通过设置cookie，header等措施，获取指定url的网页
'''
import urllib2

class Crawler(object):
    def __init__(self):
        pass
    def openUrl(self,url):
        resp=None
        while resp==None:
            try:
                resp=self.onceOpenUrl(url)
                return resp
            except :
                info =sys.exc_info()
                print info[0],':',info[1]
        
    def onceOpenUrl(self,url):
        request =urllib2.Request(url)
        response =urllib2.urlopen(request,timeout=3)
        resp = response.read()
        return resp
if __name__=='__main__':
    url='http://tieba.baidu.com/p/4382754227'
    print Crawler().openUrl(url)